home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Magazine / C_Tutorial / Part-13 / PatchLib / source / include / private / patch.i < prev    next >
Encoding:
Text File  |  1997-12-13  |  11.5 KB  |  291 lines

  1.     IFND LIBRARIES_PATCHPRIVATE_I
  2. LIBRARIES_PATCHPRIVATE_I SET 1
  3. **
  4. **    Filename:    libraries/patch.i
  5. **    Release:    6.0
  6. **    Date:        13.12.97
  7. **
  8. **    (C) Copyright 1993-97 Stefan Fuchs
  9. **    All rights reserved
  10. **
  11. **      definition of patch.library PRIVATE structures
  12.  
  13.  
  14.     IFND EXEC_TYPES_I
  15.     include "exec/types.i"
  16.     ENDC
  17.  
  18.     IFND EXEC_LISTS_I
  19.     include "exec/lists.i"
  20.     ENDC
  21.  
  22.     IFND EXEC_LIBRARIES_I
  23.     include "exec/libraries.i"
  24.     ENDC
  25.  
  26.     IFND EXEC_SEMAPHORES_I
  27.     include "exec/semaphores.i"
  28.     ENDC
  29.  
  30.     IFND UTILITY_TAGITEM_I
  31.     INCLUDE "utility/tagitem.i"
  32.     ENDC
  33. ;-------------------------------------------------------------------------
  34. STACKSLOTS = 5    ; (V6) Maximum number of stacks, which can be preallocated for stackextension feature
  35.  
  36.  
  37.  STRUCTURE MasterPatch,0    ;This structure is PRIVATE
  38.     APTR    MPS_SUCC    ;Pointer to next (successor)
  39.     APTR    MPS_PRED    ;Pointer to previous (predecessor)
  40.     UBYTE    MPS_TYPE    ;MUST be MASTERTYPE
  41.     BYTE    MPS_PRI        ;Priority, for sorting             (not used)
  42.     APTR    MPS_NAME    ;pointer to libraryname
  43.     UWORD    MPS_Flags    ;see below
  44.     STRUCT    MPS_PatchHeader,MLH_SIZE    ;Listheader for Patch structures
  45.     APTR    MPS_PatchedLibraryBase        ;Pointer to patched Library
  46.     WORD    MPS_PatchedLVO            ;Library Vektor Offset in patched Library
  47.     STRUCT    MPS_OLDEntry,6            ;original entry point
  48.     APTR    MPS_PatchIORequest        ;Pointer to IORequest for CloseDevice() (if available)
  49.     APTR    MPS_SetFunctionResult        ;Pointer to result of SetFunction
  50.                         ;(only used when the UseSetFunction Bit is set)
  51.                         ;This need not equal the contents of MPS_OLDEntry, if a SetFunction Manager is installed
  52.  
  53.     STRUCT  MPS_StackSlots,(4*STACKSLOTS)    ;(V6) Array of pointers of preallocated stacks
  54.  
  55.  
  56.  LABEL MPS_SIZEOF
  57.  
  58. ;Master Patch Struct Flags
  59.  BITDEF MPS,CloseLib,0        ;Patch.library opened the library
  60.  BITDEF MPS,CloseDev,1        ;Patch.library opened the device
  61.  BITDEF MPS,IncLibUsage,2    ;Patch.library did increase library usage counter (was MPS_PatchSV)
  62.  
  63.  BITDEF MPS,Attached,3        ;Masterpatch is attached to library
  64.  BITDEF MPS,UseSetFunction,4    ;Use SetFunction for installing and removing patches
  65.  
  66. ;---------------------------
  67.  
  68.  STRUCTURE Patch,0        ;This structure is PRIVATE
  69.     APTR    PS_SUCC        ;Pointer to next (successor)
  70.     APTR    PS_PRED        ;Pointer to previous (predecessor)
  71.     UBYTE    PS_TYPE        ;may be USERTYPE, STARTTYPE, ENDTYPE, ORIGTYPE, SYSTEMTYPE
  72.     BYTE    PS_PRI        ;Priority, for sorting
  73.     APTR    PS_NAME        ;ID string, null terminated
  74.     UWORD    PS_Flags    ;see below
  75.     APTR    PS_PatchCode    ;Pointer to PatchCode (Code begins at Offset + 12)
  76.     LONG    PS_UserPatchCodeSize        ;Length of NewCode in bytes (if this field is >0 the memory starting at the UserPatch must be freed)
  77.     STRUCT    PS_RemoveHookList,LH_SIZE    ;Header of a double linked list containing
  78.                         ;hooks to be called, when a patch is finally removed
  79.     STRUCT  PS_ProjectNode,MLN_SIZE        ;ListNode identifing the Project(if any), to which the
  80.                         ;patch belongs
  81.     ULONG    PS_UserData        ;Application specific data
  82.     ULONG    PS_StackSize        ;(V6) Minimum Stacksize for this patch
  83.     UBYTE    PS_PatchCodeType    ;(V6) Type of PatchCode attached via PS_PatchCode (see below)
  84.     UBYTE    PS_Pad            ;reserved
  85.  
  86.     APTR    PS_JmpNext        ;(V6) Pointer to instruction to change, when linkage changes or NULL
  87.     APTR    PS_JmpOrig        ;(V6) Pointer to instruction to change, when linkage changes or NULL
  88.     APTR    PS_Jsr            ;(V6) Pointer to instruction to change, when linkage changes or NULL
  89.     APTR    PS_SystemEntry        ;(V6) Address to reenter patchcode or NULL
  90.  
  91.     APTR    PS_TestUsage1        ;(V6) Pointer to instruction, which is not covered by a usage counter or NULL
  92.     APTR    PS_TestUsage2        ;(V6) Pointer to instruction, which is not covered by a usage counter or NULL
  93.     APTR    PS_TestUsage3        ;(V6) Pointer to instruction, which is not covered by a usage counter or NULL
  94.  
  95.  LABEL PS_SIZEOF
  96.  
  97. ;Patch Struct PRIVATE Flags
  98.  BITDEF PS,PatchSV,0        ;Object was installed with PatchSupervisor active
  99.  BITDEF PS,OriginalType,2    ;(V6) Patch was installed with PATT_Original
  100.  BITDEF PS,InternalCall,3    ;(V6) Calling SetPatch() from internal function
  101.                 ; (SetPatchA() will always clear this flag)
  102.  
  103. ;PS_PatchCodeType:
  104. PCODE_GENERIC    =  0    ;
  105. PCODE_START    =  6    ;For PS_TYPE_START
  106. PCODE_ORIG    =  7    ;For PS_TYPE_ORIG
  107. PCODE_END    =  8    ;For PS_TYPE_END
  108. PCODE_USER0    = 10    ;For PS_TYPE_USER   ->Replace + No UseXResult
  109. PCODE_USER1    = 11    ;For PS_TYPE_USER   ->Replace + UseXResult
  110. PCODE_USER2    = 12    ;For PS_TYPE_USER   ->Pri <> 0 + NoOrig + No UseXResult
  111. PCODE_USER3    = 13    ;For PS_TYPE_USER   ->Pri <> 0 + NoOrig + UseXResult
  112. PCODE_USER4    = 14    ;For PS_TYPE_USER   ->Pri >  0 + Orig + No UseXResult
  113. PCODE_USER5    = 15    ;For PS_TYPE_USER   ->Pri >  0 + Orig + UseXResult
  114.  
  115. PCODE_SYSTEM     = PCODE_USER4
  116.  
  117. ;----------------------------
  118.  
  119.  STRUCTURE PatchProject,0    ;This structure is PRIVATE
  120.     STRUCT  PPR_Node,LN_SIZE
  121.     UWORD    PPR_Flags        ;none defined yet
  122.     STRUCT    PPR_PatchListHeader,14    ;Header of a double linked list containing
  123.                     ;patches belonging to the Project
  124.     ULONG    PPR_UserData        ;Application specific data (not implemented)
  125.  
  126.  LABEL PPR_SIZEOF
  127. ;LN_TYPE: PS_TYPE_PROJECT
  128. ;LN_NAME: Name of Project
  129.  
  130. ;---------------------------
  131.  
  132.  STRUCTURE TLHeader,LH_SIZE    ;This structure is PRIVATE
  133.     ULONG    TL_Result1    ;Result1: 0 if Type: TL_TYPE_INCLUDE otherwise 1
  134.     ULONG    TL_Result2    ;Result2: 1 if Type: TL_TYPE_INCLUDE otherwise 0
  135.  
  136.  LABEL TL_SIZEOF
  137.  
  138.  
  139. ;---------------------------
  140.  
  141. ;ErrorCodes:
  142. PATERR_Ok        equ    0    ;Everything Ok
  143. PATERR_PatchInUse    equ    1    ;Patch Usecount <> 0
  144. PATERR_InvalidHandle    equ    2    ;Pointer to patch is not valid
  145. PATERR_OutOfMem        equ    3    ;Out of memory
  146. PATERR_OpenLib        equ    4    ;Failed to open requested library
  147. PATERR_FuncNotStd    equ    5    ;Function to patch is not in the standard format
  148. PATERR_PatchInstalled    equ    6    ;Can't remove patch because another program has installed a non-patch.library patch later
  149. PATERR_InvalidTags    equ    7    ;There was an error in the combination of the specified Tags
  150. PATERR_OpenDev        equ    8    ;Failed to open requested device
  151. PATERR_NoTaskList    equ    9    ;PATT_AddTask..., PATT_RemTask... PATT_TaskListType
  152.                     ;was specified for a patch, which had no PATT_CreateTaskList set
  153. PATERR_TaskListExists    equ    10    ;PATT_CreateTaskList was specified, but there already exists a TaskList
  154. PATERR_InvalidTaskList    equ    11    ;PATT_CreateTaskList was specified with a wrong parameter
  155. PATERR_PatchUnnamed    equ    12    ;PATT_PatchName with GetPatch was specified, for a patch without an IDString
  156. PATERR_NoSemaphore    equ    13    ;Could not allocate semaphore
  157.  
  158. PATERR_KickTooOld    equ    14    ;Kickstart version is too old for this function
  159. PATERR_InvalidPattern    equ    15    ;Pattern passed via PATT_AddTaskPattern is not valid
  160. PATERR_Restricted    equ    16    ;Certain tags/features may not be used when patching certain functions
  161.  
  162. ;-------------------------------------------------------------------------
  163.  STRUCTURE PatchNotifyMessage,0
  164.     STRUCT pnm_ExecMessage,MN_SIZE
  165.     ULONG  pnm_Class
  166.     UWORD  pnm_Code
  167.     APTR   pnm_Object
  168.     LABEL  PatchNotifyMessage_SIZEOF
  169.  
  170. ;-------------------------------------------------------------------------
  171. PATCHNOTIFY_CLASS    equ    $50000000
  172. ;-------------------------------------------------------------------------
  173. ;Notification codes (pnm_Code) (ignore messages with other codes):
  174. PATCOD_PatchInstalled    equ     1    ;new patch has been added
  175. PATCOD_PatchRemoved    equ    2    ;a patch has been removed
  176. PATCOD_PatchChanged    equ    3    ;attributes of a patch have been changed
  177. ;-------------------------------------------------------------------------
  178.  STRUCTURE PatchXResult,0    ;Use PatchAlloc(PS_TYPE_XRESULT) to allocate this
  179.     STRUCT pxr_Node,LN_SIZE    ;Reserved
  180.     ULONG  pxr_RegPattern    ;Which of the following register fields are used
  181.     ULONG  pxr_RegD0
  182.     ULONG  pxr_RegD1
  183.     ULONG  pxr_RegD2
  184.     ULONG  pxr_RegD3
  185.     ULONG  pxr_RegD4
  186.     ULONG  pxr_RegD5
  187.     ULONG  pxr_RegD6
  188.     ULONG  pxr_RegD7
  189.     ULONG  pxr_RegA0
  190.     ULONG  pxr_RegA1
  191.     ULONG  pxr_RegA2
  192.     ULONG  pxr_RegA3
  193.     ULONG  pxr_RegA4
  194.     ULONG  pxr_RegA5
  195.     ULONG  pxr_RegA6
  196.     UWORD  pxr_FlowControl    ;What patches follow this one (see below)
  197.     LABEL  PatchXResult_SIZEOF    ;Don't depend on this
  198. ;-------------------------------------------------------------------------
  199. ;Valid values for per_FlowControl:
  200. PATFC_Normal        equ    0    ;No change in the sequnce of patchcodes
  201. PATFC_FallBack        equ    1    ;Use original function (only valid, if PATT_Priority is NULL)
  202.  
  203. ;-------------------------------------------------------------------------
  204. ;Types:
  205. PS_TYPE_UNKNOWN        = 0    ;do not use
  206. PS_TYPE_MASTER        = 1    ;Structure is MPS Struct
  207. PS_TYPE_USER        = 2    ;this struct points to a routine that calls the user function
  208. PS_TYPE_SYSTEM        = 3    ;this struct points to a routine that was installed by the SetFunction patch
  209. PS_TYPE_DELUSER        = 4    ;this struct is PS_TYPE_USER, but should be removed
  210. PS_TYPE_DELSYSTEM    = 5    ;this struct is PS_TYPE_SYSTEM, but should be removed
  211. PS_TYPE_START        = 6    ;this struct points to a JMP
  212. PS_TYPE_ORIG        = 7    ;this struct points to a routine that calls the old routine
  213. PS_TYPE_END        = 8    ;this struct points to a RTS
  214. PS_TYPE_PROJECT        = 20    ;this struct is a Header structure to a list of PS_TYPE_USER structures belonging to one project
  215. PS_TYPE_XRESULT        = 30    ;this struct is an extended result structure
  216.  
  217.  
  218. TLI_TYPE_TASKNAME    = 3    ;LN_NAME points to TaskName
  219. TLI_TYPE_TASKID        = 4    ;LN_NAME points to Task structure
  220. TLI_TYPE_TASKPATTERN    = 5     ;LN_NAME points to Token string for MatchPattern() (V5)
  221.  
  222. ; ----------------------------------------------------------------------------
  223. ; This structure is at the high adresses (the bottom) of an extended stack
  224. ; .... stack ....
  225.  STRUCTURE PatchStack,0
  226.     ULONG PST_Reserved2        ; $CCDDEEFF
  227.     ULONG PST_Reserved1        ; $8899AABB
  228.     STRUCT PST_StackSwap,StackSwapStruct_SIZEOF    ;structure for StackSwap
  229.     ULONG PST_Usage            ; 1: this stack is in use  0: stack is free
  230.     APTR  PST_OldStack        ; Pointer to oldstack
  231.     ULONG PST_Stacksize        ; Size of this stack
  232.     APTR  PST_Magic2        ; pointer to PST_Magic1
  233.     ULONG PST_Magic1        ; magic PatchStackID 'PATC'
  234.     LABEL PatchStack_SIZEOF
  235.  
  236.  
  237.     ENUM TAG_USER+$5000+50        ;Beginning of GetPatch tags (currently PRIVATE)
  238.     EITEM PATT_NewCode        ;G: BOOL Return pointer to installed patch (newcode)
  239.                     ;    default: FALSE
  240.  
  241.  
  242.     ENUM TAG_USER+$5000+60        ;Beginning of PRIVATE tags
  243.     EITEM PATT_SYSTEM        ;I: True: Install patch in system mode
  244.                     ;    FOR PatchSetFunc *ONLY*
  245.                      ;F: APTR Return pointer to patch structure
  246.                     ;    of the given code pointer
  247.                     ;G: True: return Setfunction() result
  248.     EITEM PATT_LVO            ;F: UWORD Return pointer to master patch structure
  249.                     ;    of the given LibraryBase and LVO
  250.                     ;    if you specify this tag you must also specify
  251.                     ;    the public tag PATT_LibraryBase or PATT_LibraryName
  252.     EITEM PATT_Detach        ;S: BOOL the library for this patch has been closed
  253.                     ;    Parameter (MasterPatch structure instead of Patch struct)
  254.                     ;    FOR PatchSupervisor *ONLY*
  255.     EITEM PATT_Attach        ;S: struct Library *
  256.                     ;    Reattach a MasterStruct to a Library
  257.                     ;    Parameter (MasterPatch structure instead of Patch struct)
  258.                     ;    FOR PatchSupervisor *ONLY*
  259.  
  260. ;        PATT_LibraryBase    ;F: APTR Return pointer to master patch structure
  261.                     ;    of the given LibraryBase and LVO
  262.                     ;    if you specify this tag you must also specify
  263.                     ;    the private tag PATT_LVO
  264. ;        PATT_LibraryName    ;F: APTR Return pointer to master patch structure
  265.                     ;    of the given Libraryname and LVO
  266.                     ;    if you specify this tag you must also specify
  267.                     ;    the private tag PATT_LVO
  268.  
  269.     ENUM TAG_USER+$5000+24        ;Beginning of OBSOLETE tags
  270.     EITEM PATT_SaveRegisters    ;I:  ULONG (V4) Register Mask
  271.  
  272.  
  273. PATCHNAME    MACRO
  274.     dc.b "patch.library",0
  275.     ENDM
  276.  
  277. ;---------------------------------------------------------------
  278. ;--- FALLBACK - Call this macro instead of a 'rts' instruction
  279. ;--- in your patchcode, if you want to return to the original
  280. ;--- library code
  281. ;---------------------------------------------------------------
  282. FALLBACK    MACRO
  283.     move.l (sp),-(sp)
  284.     clr.l 4(sp)
  285.     rts
  286.  
  287.     ENDM
  288.  
  289.  
  290.     ENDC    ;LIBRARIES_PATCHPRIVATE_I
  291.